package org.main;

import org.game.controll.GWController;
import org.game.graphics.GWRenderer;
import org.game.map.GWMap;
import org.game.player.GWPlayer;
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Input;
import org.newdawn.slick.MouseListener;
import org.newdawn.slick.SlickException;

public class GWar extends BasicGame implements MouseListener {
	
	private GWMap map;
	private GWPlayer pl1, pl2;
	
	private GWRenderer renderer;
	private GWController controller;
	
	public GWar() {
		super("Genetic wars");
	}

	@Override
	public void init(GameContainer gc) throws SlickException {
		map = new GWMap();
		pl1 = new GWPlayer(1);
		pl2 = new GWPlayer(2);
		
		renderer = GWRenderer.createInstance(map, pl1, pl2);
		controller = new GWController(map, pl1, pl2);
	}
	
	@Override
	public void render(GameContainer gc, Graphics g) throws SlickException {
		renderer.draw(g);
	}

	@Override
	public void update(GameContainer gc, int i) throws SlickException {
		Input input = gc.getInput();
		if(input.isKeyPressed(Input.KEY_MINUS)) {
			GWController.TIME++;
		}
		if(input.isKeyPressed(Input.KEY_EQUALS)) {
			if(--GWController.TIME < 0) GWController.TIME = 0;
		}
		controller.action();
	}
	
	public static void main(String[] args) throws SlickException {
		
		AppGameContainer app = new AppGameContainer(new GWar());
    	app.setTargetFrameRate(60);
    	app.setDisplayMode(1001, 741, false);
    	app.start();
	}
}
